//
//  PHQRCodeViewController.m
//  PhnixHome
//
//  Created by Levy Xu on 2017/11/25.
//  Copyright © 2017年 Levy Xu. All rights reserved.
//

#import "PHQRCodeViewController.h"
#import "QQLBXScanViewController.h"
#import "CameraUtils.h"
#import "PHAddUtils.h"

@interface PHQRCodeViewController ()
@property(nonatomic, strong) UIImageView *imageView;
@property(nonatomic, strong) QMUIFillButton *scanBtn;
@end

@implementation PHQRCodeViewController

- (void)initSubviews {
    [super initSubviews];
    
    _imageView = [[UIImageView alloc] initWithImage:UIImageMake(@"scan_qrcode")];
    [self.myView addSubview:_imageView];
    
    _scanBtn = [[QMUIFillButton alloc] initWithFillType:QMUIFillButtonColorRed];
    _scanBtn.titleLabel.font = CodeFontMake(16);
    [_scanBtn setTitle:NSLocalizedString(@"btn_scan_dev_code", nil) forState:UIControlStateNormal];
    [_scanBtn addTarget:self action:@selector(scanQRAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.myView addSubview:_scanBtn];
}

- (void)viewDidLayoutSubviews {
    self.shouldShowMyView = YES;
    [super viewDidLayoutSubviews];
    
    _imageView.frame = CGRectMake(30, 30, self.myView.qmui_width - 60, self.myView.qmui_width - 60);
    
    _scanBtn.frame = CGRectMake(30, _imageView.qmui_bottom + 40, _imageView.qmui_width, 40);
}

- (void)scanQRAction:(id)sender {
    if ([CameraUtils isCameraOK]) {
        QQLBXScanViewController *addVC = [[QQLBXScanViewController alloc] init];
        [self.navigationController pushViewController:addVC animated:YES];
    }
}

- (void)setupNavigationItems {
    [super setupNavigationItems];
    self.title = GPHAddUtils.selectedTitle;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

@end
